#define _CRT_SECURE_NO_WARNINGS 1



#ifndef FILESYSTEM_H
#define FILESYSTEM_H

#include <stdio.h>
#include <string.h>
#include <time.h>

#define BLOCK_SIZE 1024
#define BLOCK_COUNT 1000
#define MAX_NAME_LEN 8
#define MAX_EXT_LEN 3
#define MAX_PATH_LEN 80
#define MAX_OPEN_FILES 10
#define MAGIC_NUMBER "10101010"

typedef struct {
    char name[MAX_NAME_LEN];
    char ext[MAX_EXT_LEN];
    unsigned char attr;
    unsigned short time;
    unsigned short date;
    unsigned short first_block;
    unsigned long size;
    char used;
} FCB;

typedef struct {
    short next_block;
} FAT_Entry;

typedef struct {
    FCB fcb;
    unsigned short dir_block;
    unsigned short dir_index;
    char path[MAX_PATH_LEN];
    int parent_index;
    unsigned long pos;
    char modified;
    char opened;
} UserOpenFile;

typedef struct {
    char magic[8];
    char info[200];
    unsigned short root_block;
    unsigned short fat_blocks;
} BootBlock;

typedef struct {
    BootBlock boot;
    FAT_Entry fat[BLOCK_COUNT];
    char data[BLOCK_SIZE * (BLOCK_COUNT - 6)];
} VirtualDisk;

extern VirtualDisk vdisk;
extern UserOpenFile open_files[MAX_OPEN_FILES];
extern int current_dir;

void startsys();
void my_format();
void my_cd(const char* dirname);
void my_mkdir(const char* dirname);
void my_rmdir(const char* dirname);
void my_ls();
int my_create(const char* filename);
void my_rm(const char* filename);
int my_open(const char* filename);
void my_close(int fd);
int my_read(int fd, void* buf, int size);
int my_write(int fd, const void* buf, int size);
void my_exitsys();

#endif

